<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- <script src="./2.js"></script> -->
  </head>
  <body>
    <h2>测试自定义类</h2>
    <my-text></my-text>
    <my-element></my-element>
    <script>
      class MyText extends HTMLElement {
        constructor() {
          super();
          this.append("我的文本");
        }
      }
      window.customElements.define("my-text", MyText);

      class MyElement extends HTMLElement {
        constructor() {
          super(); // 必须调用 super()
          // 元素初始化逻辑
          this.innerHTML = "<p>Hello, Custom Element!</p>";
        }
      }

      // 注册自定义元素
      customElements.define("my-element", MyElement);
    </script>
  </body>
</html>
